package com.consumer;

import com.consumer.utils.SendMsgUtil;
import org.apache.rocketmq.client.log.ClientLogger;
import org.apache.rocketmq.spring.autoconfigure.RocketMQAutoConfiguration;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.context.ApplicationPidFileWriter;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import com.consumer.config.FeignConfig;
import xiaohua.utils.ApplicationConstant;
import xiaohua.utils.ApplicationContextUtil;
import xiaohua.utils.JpaCrudUtil;
import xiaohua.utils.JwtUtil;
import xiaohua.utils.aspect.OperationLogAspect;
import xiaohua.utils.http.OkHttpUtils;

import javax.sql.DataSource;

/**
 * @author Liunh
 */
@EnableHystrix
@EnableEurekaClient
@EnableTransactionManagement
@EnableJpaRepositories(basePackages = "com.consumer.repository")
@EntityScan(basePackages = {"com.consumer.model.table"})
@EnableFeignClients(basePackages = {"com.consumer.feign"})
@Import({DataSourceAutoConfiguration.class, RocketMQAutoConfiguration.class, FeignConfig.class})
public class RocketMqConsumerApp {

    public static void main(String[] args) {
        System.setProperty(ClientLogger.CLIENT_LOG_USESLF4J, "true");
        System.setProperty(ClientLogger.CLIENT_LOG_LEVEL, "ERROR");
        SpringApplication application = new SpringApplication(RocketMqConsumerApp.class);
        application.setBannerMode(Banner.Mode.OFF);
        application.addListeners(new ApplicationPidFileWriter());
        application.run(args);
    }

    @Bean(name = "sendMsgUtil")
    public SendMsgUtil sendMsgUtil(RocketMQTemplate rocketMqTemplate) {
        return new SendMsgUtil(rocketMqTemplate);
    }

    @Bean
    public JdbcTemplate jdbcTemplate(DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

}
